import java.lang.Thread;
import java.lang.Runtime;
import java.io.*;

public class Step3 {

	Dublet_itf d;

	public static void main(String[] args) {
		Process rmireg = null;
		Process server = null;
		try {
			Runtime rt = Runtime.getRuntime();
			rmireg = rt.exec("rmiregistry");
			Thread.sleep(1000);
			server = rt.exec("java Server");
			Thread.sleep(500);
			System.out.println("Initialization.");

			System.out.println("System initialized.");

			Step3 s1 = new Step3(1);
			Step3 s2 = new Step3(2);

			s1.getOther();
		} catch(Exception exc) {
			exc.printStackTrace();
		}
	}

	public Step3(int nb) {
		Client.init();
		Dublet_itf c = (Dublet_itf)Client.lookup("Dublet");
		if(c == null) {
			c = (Dublet_itf)Client.create(new Dublet(nb));
			Client.register("Dublet", c);
		}
		this.d = c;
	}

	public void getOther() {
		d.lock_read();
		System.out.println(d.read());
		d.unlock();
	}

}
